//
//  HYServerList.m
//  HaiYue
//
//  Created by skyline on 2018/2/5.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYServerList.h"
CGFloat const TimeLBLHeight = 30;
@interface HYServerList()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, assign) CGFloat HYServerCell_H;
@end
@implementation HYServerList
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}
- (void)setList:(NSMutableArray *)list
{
    if (_list != list)
    {
        _list = list;
        [self reloadData];
    }
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableVie
{
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"HYServerCell";
    HYServerCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[HYServerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.arr = [[self.list[indexPath.section] allValues] firstObject];
    self.HYServerCell_H = cell.H;
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    return self.HYServerCell_H;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return TimeLBLHeight;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    
    HYFillLabel *label = [[HYFillLabel alloc]initWithFrame:CGRectMake(0, 0, 60, TimeLBLHeight - 5) typeOfshapeLayer:CCShapeLayerTypeRightHalfEllipse
                                                 attribute:@{HYTextColor:[UIColor whiteColor],HYTextFont:[UIFont systemFontOfSize:13]}];
    
    label.text = [[self.list[section] allKeys] firstObject];
    NSLog(@" ======= %@",label.text);
//    label.backgroundColor = (section == 1)?RGBA(235, 50, 35, 1):label.backgroundColor;
    label.backgroundColor = THEME_COLOR;
    [view addSubview:label];
    [label mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(view);
        make.left.equalTo(view);
        make.size.mas_equalTo(label.bounds.size);
    }];
    return view;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
